#include "packetdata.h"

PacketData::PacketData()
{
    stream = new QDataStream(&data,QIODevice::ReadWrite);
}

PacketData::PacketData(QByteArray d)
{
    data = d;
    stream = new QDataStream(&data,QIODevice::ReadWrite);
}

PacketData::~PacketData()
{
	delete stream;
}

QString PacketData::nextString()
{
    QString str;
    *stream >> str;
    return str;
}

qint32 PacketData::nextInt()
{
    qint32 n;
    *stream >> n;
    return n;
}

qreal PacketData::nextReal()
{
	qreal r;
	*stream >> r;
	return r;
}

void PacketData::appendString(const QString& s)
{
    *stream << s;
}

void PacketData::appendInt(const qint32& n)
{
    *stream << n;
}

void PacketData::appendReal(const qreal& r)
{
	*stream << r;
}

bool PacketData::atEnd()
{
    return stream->atEnd();
}

const QByteArray& PacketData::getData() const
{
    return data;
}
